from django.shortcuts import render

# Create your views here.
from drf_haystack.viewsets import HaystackViewSet
from rest_framework.filters import OrderingFilter
from rest_framework.generics import ListAPIView

from goods.models import SKU
from goods.serializers import SKUSerializers, SKUSearchSerializers
from goods.utils import StandardResultsSetPagination


class SKUListView(ListAPIView):

    serializer_class = SKUSerializers
    # queryset = SKU.objects.filter(ca)
    # def get(self,request):
    pagination_class = StandardResultsSetPagination  # 分页
    filter_backends = [OrderingFilter]   # 排序
    ordering_fields=['price','create_time','sales']
    def get_queryset(self):
        pk=self.kwargs['pk']
        return SKU.objects.filter(category_id=pk,is_launched=True)

class SKUSearchView(HaystackViewSet):
    # pagination_class = StandardResultsSetPagination

    index_models = [SKU]
    serializer_class = SKUSearchSerializers
